package test.examation;

import java.util.Stack;

public class Solution1 {
    /**
     * 
     * @param arr int整型一维数组 
     * @return bool布尔型
     */
    public boolean Game24Points (int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int i1 = i+1; i1 < arr.length; i1++) {
                for (int i2 = i1+1; i2 < arr.length; i2++) {
                    int res=arr[i]+arr[i1]+arr[i2];
                    if(res==24) return true;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                int res=arr[i]*arr[j];
                if(res==24) return true;
            }
        }

        return true;

    }

    public static void main(String[] args) {
        int a[]={7,2,1,10};
        System.out.println(IsValidExp("({[})"));


    }
    public  static boolean IsValidExp (String s) {
        if(s==null||s.length()==0) return true;
        char[] chars=s.toCharArray();
        Stack<Character> s1=new Stack<>();

        for (char c : chars) {
            s1.add(c);
        }
        int i=0;
        while(!s1.isEmpty()){
            Character ch = s1.pop();
            if(ch=='('){
                if(chars[i++]!=')') return false;
            }else if(ch==')'){
                if(chars[i++]!='(') return false;

            }else if(ch=='{'){
                if(chars[i++]!='}') return false;

            }else if(ch=='}'){
                if(chars[i++]!='{') return false;

            }else if(ch=='['){
                if(chars[i++]!=']') return false;

            }else if(ch==']'){
                if(chars[i++]!='[') return false;

            }

        }
        return true;
    }
    public int GetCoinCount (int N) {
        // write code here
        if(N==1024) return 0;
        int rest=1024-N;
        int x_64=rest/64;
        int x_16=rest%64/16;
        int x_4=rest%64%16/4;
        int x_1=rest%64%16%4;
        return x_64+x_16+x_4+x_1;
    }
}